package com.yt.app.api.action;

import com.yt.app.api.action.base.BaseAction;
import com.yt.app.core.interfaces.AppBannerService;
import com.yt.app.core.interfaces.AppMenuService;
import com.yt.app.core.model.AppBanner;
import com.yt.app.core.model.AppMenu;
import com.yt.app.core.utils.Constant;
import com.yt.core.MsgBean;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Api(tags = "05.自定义菜单")
@RequestMapping("/menu")
public class MenuController extends BaseAction{
    @Autowired
    private AppMenuService appMenuService;

    @ApiOperation(value="自定义菜单同步接口", httpMethod = "GET")
    @ApiResponses(value = {@ApiResponse(code = 200,message = "自定义菜单属性", response = AppMenu.class)})
    @RequestMapping("/sync")
    public @ResponseBody  Object sync(
            @ApiParam(value = "按钮ID", required = true) @RequestParam(value = "appIconId", required = false, defaultValue = "0") Long appIconId
    ){
        MsgBean msgBean = new MsgBean();
        QueryFilter filter = new DynamicSQLFilterImpl();
        filter.setPagingBean(null);
        if(appIconId >= 0){
            filter.addFilter("Q_appIconId_L_EQ", String.valueOf(appIconId));
        }
        filter.setSortField("appIconId, sort ", true);
        List<AppMenu> menuList = appMenuService.find(filter);
//        Map<Long, List<AppMenu>> map = new HashMap<Long, List<AppMenu>>();
//        List<AppMenu> list = null;
//        for(AppMenu menu : menuList){
//            list = map.get(menu.getAppIconId());
//            if(list == null) {
//                list = new ArrayList<AppMenu>();
//                map.put(menu.getAppIconId(), list);
//            }
//            list.add(menu);
//        }

        msgBean.put("menus", menuList);

        return msgBean.returnMsg();
    }


}
